using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using User.Models;
using User.Service;
using UserLogicCore.Logic;
using UserSorce.Entity.Models;

namespace User.Controllers
{
    public class MatterController : Controller
    {
        MatterService _mattersctx = new MatterService();
        private UserService _ctx = new UserService();
        InventoryServiceModels _matterServiceModels = new InventoryServiceModels();

        /// <summary>
        /// 添加事项
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="typeId"></param>
        /// <param name="inventoryId"></param>
        /// <param name="matterName"></param>
        /// <param name="overTime"></param>
        /// <param name="reamark"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddMatter(int userId, int typeId,int inventoryId ,string matterName,DateTime overTime,string reamark)
        {
            var inventory = GetInventory(userId, typeId, inventoryId);
            if (matterName==null|| overTime==null||reamark==null)
            {
                ViewData["Message"] = "输入不能为空!";
                return View("Matters", inventory);
            }
            else if (overTime <= DateTime.Now)
            {
                ViewData["Message"] = "当前时间已经超过输入时间";
            }
            else
            {
                _mattersctx.AddEvent(userId, typeId,inventoryId, matterName, overTime, reamark);
                inventory = GetInventory(userId, typeId, inventoryId);
            }
            return View("Matters", inventory);
        }
        /// <summary>
        /// 查看事项
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="typeId"></param>
        /// <param name="inventoryId"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult ShowMatter(int userId, int typeId,int inventoryId)
        {
            var inventory = GetInventory(userId, typeId, inventoryId);
            return View("Matters", inventory);
        }
        public InventorysModels GetInventory(int userId, int typeId,int inventoryId)
        {
            Users userData = _ctx.GetData(userId);
            var inventory = _matterServiceModels.TurnOffInventoryData(userData, typeId, inventoryId);
            return inventory;
        }
    }
}